home *** CD-ROM | disk | FTP | other *** search
/ GameStar 2004 April / Gamestar_61_2004-04_dvdb.iso / DVDStar / Editace / hltp.exe / {app} / Source Code / Zoners Half-Life Tools / hlvis / zones.h < prev   
C/C++ Source or Header  |  2000-09-12  |  2KB  |  76 lines

  1. // Copyright (C) 2000  Sean Cavanaugh
  2. // This file is licensed under the terms of the Lesser GNU Public License
  3. // (see LPGL.txt, or http://www.gnu.org/copyleft/lesser.txt)
  4.  
  5. #ifndef ZONING_H__
  6. #define ZONING_H__
  7.  
  8. #if _MSC_VER >= 1000
  9. #pragma once
  10. #endif
  11.  
  12. #include "basictypes.h"
  13. #include "winding.h"
  14. #include "boundingbox.h"
  15.  
  16.  
  17. // Simple class of visibily flags and zone id's.  No concept of location is in this class
  18. class Zones
  19. {
  20. public:
  21.     inline void flag(UINT32 src, UINT32 dst)
  22.     {
  23.         if ((src < m_ZoneCount) && (dst < m_ZoneCount))
  24.         {
  25.             m_ZonePtrs[src][dst] = true;
  26.             m_ZonePtrs[dst][src] = true;
  27.         }
  28.     }
  29.     inline bool check(UINT32 zone1, UINT32 zone2)
  30.     {
  31.         if ((zone1 < m_ZoneCount) && (zone2 < m_ZoneCount))
  32.         {
  33.             return m_ZonePtrs[zone1][zone2];
  34.         }
  35.         return false;
  36.     }
  37.     
  38.     void set(UINT32 zone, const BoundingBox& bounds);
  39.     UINT32 getZoneFromBounds(const BoundingBox& bounds);
  40.     UINT32 getZoneFromWinding(const Winding& winding);
  41.  
  42. public:
  43.     Zones(UINT32 ZoneCount)
  44.     {
  45.         m_ZoneCount = ZoneCount + 1;    // Zone 0 is used for all points outside all nodes
  46.         m_ZoneVisMatrix = new bool[m_ZoneCount * m_ZoneCount];
  47.         memset(m_ZoneVisMatrix, 0, sizeof(bool) * m_ZoneCount * m_ZoneCount);
  48.         m_ZonePtrs = new bool*[m_ZoneCount];
  49.         m_ZoneBounds = new BoundingBox[m_ZoneCount];
  50.  
  51.         UINT32 x;
  52.         bool* dstPtr = m_ZoneVisMatrix;
  53.         bool** srcPtr = m_ZonePtrs;
  54.         for (x=0; x<m_ZoneCount; x++, srcPtr++, dstPtr += m_ZoneCount)
  55.         {
  56.             *srcPtr = dstPtr;
  57.         }
  58.     }
  59.     virtual ~Zones()
  60.     {
  61.         delete[] m_ZoneVisMatrix;
  62.         delete[] m_ZonePtrs;
  63.         delete[] m_ZoneBounds;
  64.     }
  65.  
  66. protected:
  67.     UINT32       m_ZoneCount;
  68.     bool*        m_ZoneVisMatrix;  // Size is (m_ZoneCount * m_ZoneCount) and data is duplicated for efficiency
  69.     bool**       m_ZonePtrs;    // Lookups into m_ZoneMatrix for m_ZonePtrs[x][y] style;
  70.     BoundingBox* m_ZoneBounds;
  71. };
  72.  
  73. Zones* MakeZones();
  74.  
  75. #endif
  76.